// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: xguo

#include "coin2/exchange/base/order/message_bus.h"

namespace coin2::exchange::base::order {

void MessageBus::Subscribe(const std::string& channel, const Callback& callback) {
  channel_map_[channel].push_back(callback);
}

void MessageBus::PublishEvent(const std::string& channel, void* event_data) {
  if (channel_map_.count(channel) > 0) {
    for (auto cb : channel_map_[channel]) {
      cb(channel, event_data);
    }
  }
}

bool MessageBus::has_channel(const std::string& channel) const {
  if (channel_map_.count(channel) == 0) {
    return false;
  }
  return channel_map_.at(channel).size() > 0;
}

}  // namespace coin2::exchange::base::order
